<?php
########################################################
# DMS Donations Management System v1.0                 #
# created by:  Isaac Sabas                             #
#			   Nikko Reyes							   #
#			   Miko Tiamwatt						   #
#                                                      #
# De La Salle Philippines                              #
# All Rights Reserved DLSP Copyright 2009              #
########################################################

define('ACCESS', true);	

session_start();	
	
# set error checking levels #	
	# enable these lines when site is o be deployed #	
	ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'On');
    //ini_set('log_errors', 'On');
    //ini_set('error_log', '/usr/local/apache/logs/error_log');
	
	#############################
	# include some needed files #
	#############################
		$absRoot = '../../';
		include($absRoot . 'lib/XAJAX/xajax_core/xajax.inc.php');
		include($absRoot . 'src/ClientHandle.php');

	$id = $_GET["client_id"];

	$client = new ClientHandle();

	$ProfileArray=$client->getClientProfile($id);

	$Gender=$ProfileArray["client_gender"];
	
	if($Gender=="Male")
	{	
	$male="selected";
	$female="";
	}
	else
	if($Gender=="Female")
	{
		$female="selected";
		$male="";
	}

# instantiate predifined classes #											
	$xajax = new xajax();

	$xajax->registerFunction("editClientGender");
	
	function editClientGender($gender, $id) {
		$statusresponse = new xajaxResponse();
		
		# check if the fields are empty
			if (empty($gender)) {
				$statusresponse->assign('Status','style.color','red');
				$statusresponse->assign('Status', 'innerHTML', 'Please complete all fields.<br /> Not updating..');
			}
			else {
			
			$client = new ClientHandle();

			$ProfileArray=$client->getClientProfile($id);

			$Gender=$ProfileArray["client_gender"];	
				
					if (strcmp($Gender, $gender)==0) {
						$statusresponse->assign('Status','style.color','orange');
						$statusresponse->assign('Status', 'innerHTML', 'No changes is made.<br /> Not updating..');
					}
					elseif ($id != '') {
							
						$result = $client->setProfileValue('client_gender', $gender, $id);
						if($result == true)
						{
							$statusresponse->call("parent.window.frames['view_client_profile_".$id."'].location.reload()");
							$statusresponse->assign('Status','style.color','green');
							$statusresponse->assign('Status', 'innerHTML', 'Client gender changed.<br /> Database updated.');
						}
						else
						{
						$statusresponse->assign('Status','style.color','red');
						$statusresponse->assign('Status', 'innerHTML', 'Please complete all fields.<br />Not updating..');	
						}
					}
			
			}
			
								
		return$statusresponse;
	}
	$xajax->processRequest();	

	//print_r($result);
?>

<html>
<head>
	<script type="text/javascript" src="../../lib/XAJAX/xajax_js/xajax_core.js" />
	<link rel="stylesheet" type="text/css" href="../../lib/YUI/yui/build/fonts/fonts-min.css" />
	<?php $xajax->printJavaScript(); ?>
</head>
<body>											


<form id="EditClientGender" action="#" method='post'>
<table>
	
	<tr>
	<td>
	Gender:</td>
	<td>
			<select id="Gender" name="Gender">
			<option value="Male" <?php echo $male;?>>Male</option>
			<option value="Female" <?php echo $female;?>>Female</option>
		</select>
	</td>
	</tr>
	<tr>
	<td>
	</td>
	<td>
	<input type=button id="Update" value="Update" onclick="xajax_editClientGender(document.getElementById('Gender').value, <?php echo $id;?>);"></input>
	<input type=reset id="Reset" value="Reset"></input>
	</td>
	</tr>
	
	
</table>

</form>
<div id='Status'></div>

</body>

</html>
